!function (e, $, mui) {
    "use strict";
	var config = {
	};
	// 定义页面
	var p = function(config) {
		var t = this;
		t.config = config;
		t.userInfo = null;
		t.page = {
			page: 0,
			perpage: 0,
			more: true
		};
		t.element = {
			listContainer: $('#list-container .list'),
			emptyContainer: $('#list-container .empty-list'),
		};
		// 初始化
		t.init();
		
		// 事件监听
		t.listen();
	};
	
	var pt = p.prototype;
	
	// 页面初始化
	pt.init = function () {
		var t = this;
		t.userInit();
		// 列表加载
//		t.listInit();
	};
	
	// 事件初始化
	pt.listen = function() {
		var t = this;
		// 刷新列表
		t.element.emptyContainer.on('tap', function () {
			t.listInit();
		});
	};
	
	// 列表初始化
	pt.listInit = function() {
		var t = this;
		t.element.listContainer.html('');
		t.page = {
			page: 0,
			per_page: 10,
			more: true
		};
		
		// 列表加载
		t.listLoad();
	};
	
	// 列表加载
	pt.listLoad = function() {
		var t = this;
		t.page.page++;
		
		if(t.page.more === false) {
            mui('#list-container').pullRefresh().endPulldownToRefresh();
            mui('#list-container').pullRefresh().endPullupToRefresh();
			return;
		}
		
		baseApi.get(
		'service/suggestion',
		{
			page: t.page.page,
			per_page: t.page.per_page
		},
		function (result) {
			var i = 0;
			result.data.forEach(function (item) {
				i++;
				var html = '<li class="mui-table-view-cell mui-collapse">';
				html += '<a class="mui-navigate-right" href="#">';
				html += '<div class="mui-media-body mui-col-xs-9 information2 mui-pull-left">';
				html += item.title;
				html += '</div>';
				html += '<span class="information1 mui-text-right mui-col-xs-3 mui-pull-right">'+item.create_time_format+'</span>';
				html += '</a>';
				html += '<div class="mui-collapse-content"><pre>';
				html += item.content;
				html += '</pre></div>';
				html += '</li>';
				t.element.listContainer.append(html);
			});
			
			// 判断列表是否为空
			if(t.page.page == 1) {
				if(i > 0) {
					t.element.listContainer.show();
					t.element.emptyContainer.hide();
				} else {
					t.element.listContainer.hide();
					t.element.emptyContainer.show();
				}
			}
			
			if(i < t.page.perpage) {
				t.page.more = false;
				mui('#list-container').pullRefresh().disablePullupToRefresh();
			} else {
				mui('#list-container').pullRefresh().enablePullupToRefresh();
			}
			mui('#list-container').pullRefresh().endPulldownToRefresh();
			mui('#list-container').pullRefresh().endPullupToRefresh();
		});
	};
	
	// 用户信息初始化
	pt.userInit = function() {
		var t = this;
		t.userInfo = getLocalUserInfo();
	};
	
	e.page = new p(config);
	mui.init({
		pullRefresh: {
			container: '#list-container',
			down: {
				style: 'circle',
				callback: function () {
					e.page.listInit();
				}	// 下拉刷新
			},
			up: {
				auto: false,
				contentrefresh: '正在加载...',
				callback: function () {	// 上拉加载
					e.page.listLoad();
				}
			}
		}
	});
	
	// 登录判断
	checkUserLogin();
	e.page.listInit();
		

}(window, $, mui);